<template>
  <div class="pxy20">
    <ElButton type="primary" @click="addArticle">新增案例</ElButton>

    <ElTable :data="list" border style="margin-top: 20px">
      <ElTableColumn
        label="序号"
        type="index"
        align="center"
        width="70"
      ></ElTableColumn>
      <ElTableColumn
        label="案例名称"
        prop="title"
        align="center"
      ></ElTableColumn>
      <ElTableColumn
        label="案例类别"
        prop="type"
        align="center"
        width="250"
      ></ElTableColumn>

      <ElTableColumn
        label="学校"
        prop="school"
        width="200"
        align="center"
      ></ElTableColumn>
      <ElTableColumn
        label="创建时间"
        prop="createTime"
        align="center"
        width="270"
      ></ElTableColumn>
      <ElTableColumn label="操作" width="300">
        <template slot-scope="{ row }">
          <div>
            <ElButton type="primary" @click="edit(row)">编辑</ElButton>
            <ElButton type="danger" @click="del(row)">删除</ElButton>
          </div>
        </template>
      </ElTableColumn>
    </ElTable>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.size"
      @pagination="getList"
    />
  </div>
</template>
<script>
import { CASE_DEL } from "@/api/ACAI/case";
import { GET_QA_LIST } from "@/api/ACAI/qa";
import Pagination from "@/components/Pagination";
export default {
  name: "caseIndex",
  components: { Pagination },
  data() {
    return {
      list: [],
      total: 0,
      listQuery: {
        page: 1,
        size: 10,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      GET_QA_LIST(this.listQuery).then((res) => {
        let { total, rows } = res.data;
        this.list = rows;
        this.total = total;
      });
    },
    addArticle() {
      this.$router.push({ name: "caseEdit" });
    },
    edit(row) {
      this.$router.push({ name: "caseEdit", params: row });
    },
    del(row) {
      let ids = row.id;
      CASE_DEL({ ids }).then((res) => {
        let i = res["result"] == 0;
        this.$message({
          message: i ? "删除成功！" : "删除失败!" + res.msg,
          type: i ? "success" : "error",
        });
        i ? this.getList() : "";
      });
    },
  },
};
</script>
<style lang="scss" scoped></style>
